package cn.zjj._01_sync;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
 * 生产者
 */
public class Sync_Producer {


    public static void main(String[] args) throws Exception{
        //1.准备生产者对象
        DefaultMQProducer producer = new DefaultMQProducer("sync_producer_group");
        //2.设置nameserver 注册中心: 管家,调度,需要什么去他这儿,但是它不做事
        producer.setNamesrvAddr("localhost:9876");
        //3.启动
        producer.start();
        //4.创建消息对象,发送消息    topic:主题名,消费时需要主题名才能消费该消息
        Message message = new Message("sync","hellojava","你好,世界!".getBytes(StandardCharsets.UTF_8));
        SendResult send = producer.send(message);
        System.out.println(send);
        //5.关闭
        producer.shutdown();
    }
}
